package weak_20241227_29.stream;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Optional;

/**
 * @author zdl
 * @date 2024/12/27
 */
public class Demo13 {
    public static void main(String[] args) {
        //13. 从字符串列表中找出最长的字符串
        ArrayList<String> list = new ArrayList<>();
        list.add("qwe");
        list.add("qwerty");
        list.add("qweokhccc");
        list.add("qweok");
        Optional<Integer> max2 = list.stream().map(s -> s.length()).max((w1, w2) -> w1 - w2);
        Optional<String> max = list.stream().max(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return Integer.compare(o1.length(),o2.length());
            }
        });
        Optional<String> max1 = list.stream().max((w1, w2) -> Integer.compare(w1.length(), w2.length()));
        System.out.println(max1.get());
    }
}
